<template>
  <div>
    <div class="main">
      <eagle-radio-group
        required
        label="应急职务"
        v-model="form.TeamMemberType"
        name="IncludingWeekend"
        direction="horizontal"
        :dataSource="form.TeamMemberTypeList"
      ></eagle-radio-group>
      <eagle-input
        class="input_text"
        label="成员姓名"
        placeholder="请输入"
        isInputText
        v-model="form.TeamMemberName"
        required
      >
      </eagle-input>
      <eagle-input
        class="input_text"
        label="成员电话"
        placeholder="请输入"
        isInputText
        v-model="form.TeamMemberPhone"
        required
      >
      </eagle-input>
      <eagle-input
        class="input_text"
        label="班次"
        placeholder="请输入"
        v-model="form.Shift"
      >
      </eagle-input>
      <eagle-input
        class="input_text"
        label="平时职务"
        placeholder="请输入"
        v-model="form.Position"
      >
      </eagle-input>
      <eagle-date
        label="加入日期"
        :date.sync="form.JoinDate"
      ></eagle-date>
      <div class="btn_submit">
        <eagle-button block type="primary" @click="_submit">
          保存
        </eagle-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.query.id,
      code: this.$route.query.code,
      filter: {
        id: this.$route.query.id,
      },
      form: {},
    };
  },
  created() {
    if (this.id > 0) {
      this.getDetail();
    } else {
      this.initData();
    }
  },
  methods: {
    getDetail() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeamMember/GetDetail",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
        _this.form.EmergencyTeamCode = _this.code;
      });
    },
    //初始化实体
    initData() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeamMember/InitNewEntity",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
        _this.form.EmergencyTeamCode = _this.code;
      });
    },
    // 保存
    _submit() {
      if (!this.form.TeamMemberType) {
        this.$toast("请选择应急职务");
        return;
      }
      if (!this.form.TeamMemberName) {
        this.$toast("请输入成员姓名");
        return;
      }
      if (!this.form.TeamMemberPhone) {
        this.$toast("请输入成员电话");
        return;
      }
      let _this = this;
      let params=_this.form;
      _this.$axios
      .post("/PlanEmergencyOrgTeamMember/PostData",params)
        .then((res) => {
          _this.$toast("保存成功");
          _this.loading = false;
          setTimeout(() => {
            _this.$router.goRefresh();
          }, 500);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
</style>
<style lang="less" scoped>
.space-between {
  justify-content: space-between;
}
</style>
